$(function(){
	function loadCart(){
		var cartStr=$.cookie("cart")?$.cookie("cart"):"";
		var cartObj=convertCartStrToObj(cartStr);
		//获取到购物车中所有商品的数量
		var total=0;
		for(var id in cartObj){
			total+=cartObj[id].num;
		}
		$(".top_right_span1").html(total);
		$(".top_right_span1").val(total);
	}
loadCart()
})
function convertCartStrToObj(cartStr){
		if(!cartStr){
			return {};
		}
		var goods=cartStr.split(":");
		var obj={};
		for(var i=0;i<goods.length;i++){
			var data=goods[i].split(",");
			//以商品的id为健 商品的其他信息为值
			obj[data[0]]={
				name:data[1],
				price: parseFloat(data[2]),
				num:parseInt(data[3]),
				src:data[4]
			}
		}
		return obj;
	}
	function convertObjToCartStr(obj){
		var cartStr="";
		//遍历对象
		for(var id in obj){
			if(cartStr){
				cartStr+=":"
			}
			cartStr+=id+","+obj[id].name+","+obj[id].price+","+obj[id].num+","+obj[id].src+",";
			
		}
		return cartStr
	}


